log_access_to_file('square.js');

// La singola cella di gioco
var Square = {
	construct : function(character, tableCell) {
		this.background = "empty";
		if (character == "#")
			this.background = "wall";
		else if (character == "*")
			this.background = "exit";

		this.tableCell = tableCell;
		this.tableCell.className = this.background;

		this.content = null;
		if (character == "0")
			this.content = "boulder";
		else if (character == "@")
			this.content = "player";

		if (this.content != null) {
			var image = dom("IMG", {
				src : "img/sokoban/" + this.content + ".gif"
			});
			this.tableCell.appendChild(image);
		}
	},

	hasPlayer : function() {
		return this.content == "player";
	},
	hasBoulder : function() {
		return this.content == "boulder";
	},
	isEmpty : function() {
		return this.content == null && this.background == "empty";
	},
	isExit : function() {
		return this.background == "exit";
	}
};

Square.moveContent = function(target) {
  target.content = this.content;
  this.content = null;
  target.tableCell.appendChild(this.tableCell.lastChild);
};

Square.clearContent = function() {
  self.content = null;
  var image = this.tableCell.lastChild;
  var size = 100;

  var animate = setInterval(function() {
    size -= 10;
    image.style.width = size + "%";
    image.style.height = size + "%";

    if (size < 20) {
      clearInterval(animate);
      removeElement(image);
    }
  }, 50);
};